package com.ruoyi.car.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.car.domain.CarVehicleRecord;
import com.ruoyi.car.service.ICarVehicleRecordService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 用车记录Controller
 * 
 * @author ruoyi
 * @date 2022-12-03
 */
@RestController
@RequestMapping("/car/vehicleRecord")
public class CarVehicleRecordController extends BaseController
{
    @Autowired
    private ICarVehicleRecordService carVehicleRecordService;

    /**
     * 查询用车记录列表
     */
    @PreAuthorize("@ss.hasPermi('car:vehicleRecord:list')")
    @GetMapping("/list")
    public TableDataInfo list(CarVehicleRecord carVehicleRecord)
    {
        startPage();
        List<CarVehicleRecord> list = carVehicleRecordService.selectCarVehicleRecordList(carVehicleRecord);
        return getDataTable(list);
    }

    /**
     * 导出用车记录列表
     */
    @PreAuthorize("@ss.hasPermi('car:vehicleRecord:export')")
    @Log(title = "用车记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CarVehicleRecord carVehicleRecord)
    {
        List<CarVehicleRecord> list = carVehicleRecordService.selectCarVehicleRecordList(carVehicleRecord);
        ExcelUtil<CarVehicleRecord> util = new ExcelUtil<CarVehicleRecord>(CarVehicleRecord.class);
        util.exportExcel(response, list, "用车记录数据");
    }

    /**
     * 获取用车记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('car:vehicleRecord:query')")
    @GetMapping(value = "/{vehicleRecordId}")
    public AjaxResult getInfo(@PathVariable("vehicleRecordId") Long vehicleRecordId)
    {
        return success(carVehicleRecordService.selectCarVehicleRecordByVehicleRecordId(vehicleRecordId));
    }

    /**
     * 新增用车记录
     */
    @PreAuthorize("@ss.hasPermi('car:vehicleRecord:add')")
    @Log(title = "用车记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CarVehicleRecord carVehicleRecord)
    {
        return toAjax(carVehicleRecordService.insertCarVehicleRecord(carVehicleRecord));
    }

    /**
     * 修改用车记录
     */
    @PreAuthorize("@ss.hasPermi('car:vehicleRecord:edit')")
    @Log(title = "用车记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CarVehicleRecord carVehicleRecord)
    {
        return toAjax(carVehicleRecordService.updateCarVehicleRecord(carVehicleRecord));
    }

    /**
     * 删除用车记录
     */
    @PreAuthorize("@ss.hasPermi('car:vehicleRecord:remove')")
    @Log(title = "用车记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{vehicleRecordIds}")
    public AjaxResult remove(@PathVariable Long[] vehicleRecordIds)
    {
        return toAjax(carVehicleRecordService.deleteCarVehicleRecordByVehicleRecordIds(vehicleRecordIds));
    }
}
